// Basic constants needed by our app
DefConst('kAppName, "newPage");
DefConst('kAppSymbol, '|newPage:cognisense|);
DefConst('kIconFile, Home & "newPage.rsrc");



// Define the button and it's functionality
refNum := OpenResFileX(kIconFile); 
DefConst('kpartData, {
    _proto: protoPictureButton,
    idTag: kAppSymbol,
    viewBounds: {top: 2, left: 8, right: 22, bottom: 15},
    viewJustify: vjCenterH + vjCenterV + vjSiblingRightH,
    buttonClickScript: func()
        begin
			local t:= GetUnionSoup("Notes");
			local lastItem := GetRoot().paperroll.lastItem;
            local myHeight:= 40;
            local myData:=[];
            if not (lastItem.data) then 
				lastItem.height := myHeight;
            else 
				begin
					if (Length(lastItem.data) > 0) then
						begin
							local lastDataItem := lastItem.data[Length(lastItem.data)-1];
							local noteType := lastDataItem.viewStationery;
							
							if (noteType exists AND noteType = 'para) then 
								lastItem.height := lastDataItem.viewBounds.bottom + 30;
						end;
				end;
            local myEntry:={viewStationery: 'paperRoll,
                            height: lastItem.height,
                            data: myData,
                            timeStamp:time(),
                            modTime:time()};
            local myLabel:=GetRoot().paperroll.lastItem.labels;                
			if (myLabel exists AND myLabel <> nil) then
				myEntry.labels := myLabel;
            t:AddToDefaultStore(myEntry);
            broadcastSoupChange("Notes");
            GetRoot().paperroll:viewScrollDownScript();
        end,
    icon: GetPictAsBits("newPageIcon", nil),
});
CloseResFileX(refNum);


InstallScript := func(partFrame)
begin
	local statusBar := GetRoot().KeyboardChicken:Parent();
	
	if (NOT HasSlot(statusBar, 'stepChildren)) then
		statusBar.(EnsureInternal('stepChildren)) := Clone(statusBar.viewChildren);
	
	local tTemplate := EnsureInternal({_proto: nil, tag: kAppSymbol});
	tTemplate._proto := kpartData;
	
	AddArraySlot(statusBar.stepChildren, tTemplate);
	
	if (Visible(statusBar)) then
		statusBar:RedoChildren();
end;

RemoveScript := func(removeFrame)
begin
	local statusBar := GetRoot().KeyboardChicken:Parent();

	if (NOT HasSlot(statusBar, 'stepChildren)) then
		return;
		
	foreach stepChild in statusBar.stepChildren do
	begin
		if HasSlot(stepChild, 'tag) then
			if (stepChild.tag = kAppSymbol) then
			begin
				local tCompareFunction := func(sTag, stepChildFrame)
												if (stepChildFrame.tag = sTag) then TRUE;
				local tPos := ArrayPos(statusBar.stepChildren, kAppSymbol, 0, tCompareFunction);
				if (tPos) then
					RemoveSlot(statusBar.stepchildren, tPos);
				
				break;
			end;
	end;

	if Visible(statusBar) then
		statusBar:RedoChildren();
end;






"magic llama"

